package control;

import model.Model;
import sginUp.SginUp;
import view.GameFrame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import static model.Model.choose;
import static model.Model.num;

public class MouseAction implements ActionListener {
    Model model;
    GameFrame gameFrame;

    Random random = new Random();
    private JMenuItem Figure;

    private JMenuItem Sheep;

    private JMenuItem SpongeBob;
    //重新登录项
    private JMenuItem replay;
    //重新游戏项
    private JMenuItem logout;
    //关闭游戏项
    private JMenuItem exit;

    private JMenuItem author;

    public MouseAction(GameFrame gameFrame,Model model) {
        this.gameFrame = gameFrame;
        this.model = model;
    }

    public void setFigure(JMenuItem figure) {
        Figure = figure;
    }

    public void setSheep(JMenuItem sheep) {
        Sheep = sheep;
    }

    public void setSpongeBob(JMenuItem spongeBob) {
        SpongeBob = spongeBob;
    }

    public void setReplay(JMenuItem replay) {
        this.replay = replay;
    }

    public void setLogout(JMenuItem logout) {
        this.logout = logout;
    }

    public void setExit(JMenuItem exit) {
        this.exit = exit;
    }

    public void setAuthor(JMenuItem author) {
        this.author = author;
    }

    //动作监听
    @Override
    public void actionPerformed(ActionEvent e) {
        //获取动作监听的项
        Object control = e.getSource();
        //更换图片
        if (control == Figure) {
            choose = "Figure\\figure";
            num = (random.nextInt(3) + 1) + "\\";
            model.reStart();
        } else if (control == Sheep) {
            choose = "Sheep\\sheep";
            num = (random.nextInt(3) + 1) + "\\";
            model.reStart();
        } else if (control == SpongeBob) {
            choose = "SpongeBob\\spongbob";
            num = (random.nextInt(3) + 1) + "\\";
            model.reStart();
        } else if (control == replay) {
            model.reStart();
        } else if (control == logout) {
            gameFrame.setVisible(false);
            new SginUp();
        } else if (control == exit) {
            System.exit(0);
        } else if (control == author) {
            JOptionPane.showMessageDialog(gameFrame,"姓名:朱倩如 学号：221107410096\n姓名:阚雅馨 学号：221107410080","作者",JOptionPane.PLAIN_MESSAGE);	//消息对话框

        }
    }
}
